package com.google.gwt.homepage.smile.client.view;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;



import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.HTMLTable;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.homepage.smile.client.presenter.EnneagramTestPresenter;
import com.google.gwt.homepage.smile.shared.EnneagramTestResultBean;
import com.google.gwt.i18n.client.Constants;
import com.google.gwt.i18n.client.LocaleInfo;

import com.google.gwt.homepage.smile.shared.EnneagramQuestions;

import java.util.ArrayList;
import java.util.List;

public class EnneagramTestView extends Composite implements EnneagramTestPresenter.Display {
  
	
	
	/**
	   * The constants used in this Widget.
	   */
	  
	  public static interface CwConstants extends Constants {
		String enneagramTestTitle();
		String enneagramTestDesc();
	  }
	
	  private CwConstants constants;
	  
	  
	//private final Button addButton;
  //private final Button deleteButton;
  //private FlexTable contactsTable;
  private final FlexTable contentTable;
  private SimplePanel contentArea ;
  /**
   * The default style name.
   */
  private static final String DEFAULT_STYLE_NAME = "sc-ContentWidget";
	
  
  public EnneagramTestView(CwConstants constants) {
	  
	  this.constants=constants;
	  
	  
    //DecoratorPanel contentTableDecorator = new DecoratorPanel();
	  VerticalPanel contentTableDecorator = new VerticalPanel();
    initWidget(contentTableDecorator);
    contentTableDecorator.setWidth("100%");
    
    //contentTableDecorator.setWidth("18em");

    contentTable = new FlexTable();
    contentTable.setWidth("100%");
    contentTable.getCellFormatter().addStyleName(0, 0, "contacts-ListContainer");
    contentTable.getCellFormatter().setWidth(0, 0, "100%");
    contentTable.getFlexCellFormatter().setVerticalAlignment(0, 0, DockPanel.ALIGN_TOP);
    
    
    //
    // Create submenu, description
    VerticalPanel widgetVpanel = new VerticalPanel();
    contentTable.setWidget(0, 0, widgetVpanel);

    // Add the name
    HTML nameWidget = new HTML(constants.enneagramTestTitle());
    nameWidget.setStyleName(DEFAULT_STYLE_NAME + "-name");
    widgetVpanel.add(nameWidget);

    // Add the description
    //HTML descWidget = new HTML("You can test Enneagram( total 180 question.  It takes about 15minute.)");
    HTML descWidget = new HTML(constants.enneagramTestDesc());
    descWidget.setStyleName(DEFAULT_STYLE_NAME + "-description");
    widgetVpanel.add(descWidget);
    
    /*복원
    EnneagramTestWidget calendar = new EnneagramTestWidget(7);
    contentTable.setWidget(1, 0, calendar);
    contentTableDecorator.add(contentTable);
    */
    contentArea= new SimplePanel();
    contentTable.setWidget(1, 0, contentArea);
    contentTableDecorator.add(contentTable);
   
  }
  /*
  public HasClickHandlers getAddButton() {
    return addButton;
  }
  
  public HasClickHandlers getDeleteButton() {
    return deleteButton;
  }
  
  public HasClickHandlers getList() {
    return contactsTable;
  }

  public void setData(List<String> data) {
    contactsTable.removeAllRows();
    
    for (int i = 0; i < data.size(); ++i) {
      contactsTable.setWidget(i, 0, new CheckBox());
      contactsTable.setText(i, 1, data.get(i));
    }
  }
  
  public int getClickedRow(ClickEvent event) {
    int selectedRow = -1;
    HTMLTable.Cell cell = contactsTable.getCellForEvent(event);
    
    if (cell != null) {
      // Suppress clicks if the user is actually selecting the 
      //  check box
      //
      if (cell.getCellIndex() > 0) {
        selectedRow = cell.getRowIndex();
      }
    }
    
    return selectedRow;
  }
  
  public List<Integer> getSelectedRows() {
    List<Integer> selectedRows = new ArrayList<Integer>();
    
    for (int i = 0; i < contactsTable.getRowCount(); ++i) {
      CheckBox checkBox = (CheckBox)contactsTable.getWidget(i, 0);
      if (checkBox.getValue()) {
        selectedRows.add(i);
      }
    }
    
    return selectedRows;
  }
  */
  
  public HasWidgets getContentWidget(){//컨텐츠가 들어갈 부분을 가져옴( 이 영역에 EnneagramTestWidget, EnneagramResultWidget가 들어감
	  return contentArea;
  }
  
  

  
  
  
  public Widget asWidget() {
    return this;
  }
}
